VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "itgcontrols.ocx"
Begin VB.Form frmITGPicker3 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "ITGPicker"
   ClientHeight    =   3945
   ClientLeft      =   -105
   ClientTop       =   -120
   ClientWidth     =   8100
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3945
   ScaleWidth      =   8100
   StartUpPosition =   1  'CenterOwner
   Begin VB.Frame fraSearch 
      Caption         =   "Primary Search Column"
      Height          =   495
      Left            =   1905
      TabIndex        =   4
      Top             =   3375
      Width           =   2670
      Begin VB.OptionButton optCode 
         Caption         =   "ID/Code"
         Height          =   255
         Left            =   180
         TabIndex        =   6
         Top             =   180
         Width           =   915
      End
      Begin VB.OptionButton optName 
         Caption         =   "Name/Desc"
         Height          =   255
         Left            =   1320
         TabIndex        =   5
         Top             =   180
         Width           =   1230
      End
   End
   Begin VB.TextBox txtFind 
      Appearance      =   0  'Flat
      Enabled         =   0   'False
      Height          =   285
      Left            =   45
      Locked          =   -1  'True
      TabIndex        =   3
      Top             =   3000
      Width           =   4515
   End
   Begin MSDataGridLib.DataGrid dtgList 
      Height          =   2865
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   8100
      _ExtentX        =   14288
      _ExtentY        =   5054
      _Version        =   393216
      AllowUpdate     =   -1  'True
      HeadLines       =   1
      RowHeight       =   15
      AllowAddNew     =   -1  'True
      AllowDelete     =   -1  'True
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   3
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column02 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         MarqueeStyle    =   3
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
         BeginProperty Column02 
         EndProperty
      EndProperty
   End
   Begin ITGControls.ITGCommandButton cmdCancel 
      Height          =   345
      Left            =   6120
      TabIndex        =   2
      Top             =   3525
      Width           =   1230
      _ExtentX        =   2170
      _ExtentY        =   609
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "&Cancel"
   End
   Begin ITGControls.ITGCommandButton cmdOK 
      Height          =   345
      Left            =   4860
      TabIndex        =   1
      Top             =   3525
      Width           =   1230
      _ExtentX        =   2170
      _ExtentY        =   609
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "&OK"
   End
End
Attribute VB_Name = "frmITGPicker3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'IT Group Inc. 2008.08.23

Option Explicit

Enum ePick3Type
    WSupplier
    WSupplierNT
End Enum

Public zType As ePick3Type
Public zCode As String
Public zName As String
Public sColumnVariable As String
Public sTypeVariable As String ' Myk
Public sPCCode As String ' Myk

Private rsPickList As New ADODB.Recordset
Private oConnection As New clsConnection
Private connList As ADODB.Connection

Private Sub cmdCancel_Click()
    Unload Me
    Set frmITGPicker3 = Nothing
End Sub

Private Sub cmdOK_Click()
    SelectOK
    Unload Me
End Sub

Private Sub dtgList_DblClick()
    If rsPickList.RecordCount <> 0 Then SelectOK
End Sub

Private Sub dtgList_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyEscape Then
        Unload Me
        Set frmITGPicker = Nothing
    ElseIf KeyAscii = 8 Then
        If Trim(txtFind.Text) <> "" Then
            txtFind = Mid(txtFind.Text, 1, Len(txtFind.Text) - 1)
            If txtFind <> "" Then
                FilterString True
            Else
                FilterString False
            End If
        End If
    ElseIf KeyAscii = 13 Then
        SelectOK
    ElseIf KeyAscii = 39 Then
        KeyAscii = 0
    Else
        txtFind = txtFind.Text + UCase(Chr(KeyAscii))
        If Trim(txtFind) <> "" Then
            FilterString True
            dtgList.SetFocus
        End If
    End If
End Sub

Private Sub Form_Activate()
    'If zType = QAccounts Then
    '    optCode.Value = True
    'Else
        optName.Value = True
    'End If
End Sub

Private Sub Form_Load()
    lPickListActive = True
    txtFind.Text = sFilterString
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set rsPickList = Nothing
    Set connList = Nothing
    RepName = Empty
    sFilterString = Empty
    Me.sTypeVariable = Empty
    lPickListActive = False
End Sub

Private Sub SelectOK()
    zCode = ""
    zName = ""
    
    If rsPickList.RecordCount = 0 Then Exit Sub
    
    Select Case zType
        Case WSupplier, WSupplierNT
            zCode = rsPickList!cCode
            zName = rsPickList!cName
    End Select
    Unload Me
End Sub

Private Sub FilterString(lReset As Boolean)
    With rsPickList
        If sColumnVariable = "Code" Then
            If lReset = True Then
                Select Case zType
                    Case WSupplier, WSupplierNT
                        .Filter = "cCode like '" & Trim(txtFind.Text) & "%'"
                End Select
            Else
                Select Case zType
                    Case WSupplier, WSupplierNT
                        .Filter = "cCode <> ''"
                End Select
            End If
        Else
            If lReset = True Then
                Select Case zType
                    Case WSupplier, WSupplierNT
                        .Filter = "cName like '" & Trim(txtFind.Text) & "%'"
                End Select
            Else
                Select Case zType
                    Case WSupplier, WSupplierNT
                        .Filter = "cName <> ''"
                End Select
            End If
        End If
    End With
End Sub

Public Sub ShowForm3()
On Error GoTo TheSource

    dtgList.ClearFields
    If rsPickList.State = adStateOpen Then rsPickList.Close
    DoEvents
    oConnection.OpenNewConnection connList
    'MousePointer = vbHourglass
     If Not lModal Then FormWaitShow App.Path & "\Transmit.avi", "Loading list . . ."
    Select Case zType
        Case WSupplier
            Caption = "Supplier List"
            If sColumnVariable = "Code" Then
                LoadColumn "cCode", "cName", "cTin", "CLIENT_SUPPLIER", 1, "Supplier ID", "Supplier Name", " ", "cCode"
            Else
                LoadColumn "cName", "cCode", "cTin", "CLIENT_SUPPLIER", 2, "Supplier Name", "Supplier ID", " ", "cName"
            End If
        Case WSupplierNT
            Caption = "Supplier List (Non-Trade)"
            If sColumnVariable = "Code" Then
                LoadColumn "cCode", "cName", "cTin", "CLIENT_SUPPLIER_NT", 1, "Supplier ID", "Supplier Name", " ", "cCode"
            Else
                LoadColumn "cName", "cCode", "cTin", "CLIENT_SUPPLIER_NT", 2, "Supplier Name", "Supplier ID", " ", "cName"
            End If
    End Select
    If Not lModal Then FormWaitHide
    
    lModal = False
    FilterString True
    
    'MousePointer = vbDefault
    
TheSource:
    If err.Number = 3709 Then
        Set connList = Nothing
        FormWaitHide
        'MousePointer = vbDefault
        Unload Me
    End If
End Sub

Private Sub optCode_Click()
    sColumnVariable = "Code"
    ShowForm3
    dtgList.SetFocus
End Sub

Private Sub optName_Click()
    sColumnVariable = "Desc"
    ShowForm3
    dtgList.SetFocus
End Sub

Private Sub LoadColumn(FirstArg As String, SecondArg As String, ThirdArg As String, TableArg As String, _
            CodeArg As Integer, Caption1 As String, Caption2 As String, Cond As String, OrderArg As String, Optional lWOCompany As Boolean)
    
    If lWOCompany Then
        If UCase(Left(Trim(Cond), 3)) = "AND" Then Cond = Trim(Mid(Trim(Cond), 4, Len(Trim(Cond))))
        
        If Trim(Cond) = "" Then
            sSQL = "SELECT " & FirstArg & ", " & SecondArg & ", " & ThirdArg & " FROM " & TableArg & _
                " ORDER BY " & Trim(OrderArg)
        Else
            sSQL = "SELECT " & FirstArg & ", " & SecondArg & ", " & ThirdArg & " FROM " & TableArg & _
                " WHERE " & Trim(Cond) & _
                " ORDER BY " & Trim(OrderArg)
        End If
    Else
    sSQL = "SELECT " & FirstArg & ", " & SecondArg & ", " & ThirdArg & " FROM " & TableArg & _
           " WHERE cCompanyID = '" & Trim(COID) & "' " & Trim(Cond) & _
           " ORDER BY " & Trim(OrderArg)
    End If
    
    rsPickList.Open sSQL, connList, adOpenForwardOnly, adLockReadOnly, adCmdText
    Set dtgList.DataSource = rsPickList
    With rsPickList
        dtgList.Columns(0).DataField = (FirstArg)
        dtgList.Columns(1).DataField = (SecondArg)
        dtgList.Columns(2).DataField = (ThirdArg)
    End With
    If CodeArg = 1 Then
        dtgList.Columns(0).Width = 1500
        dtgList.Columns(1).Width = 4300
    Else
        dtgList.Columns(0).Width = 4300
        dtgList.Columns(1).Width = 1500
    End If
    dtgList.Columns(2).Width = 2000
    
    dtgList.Columns(0).Caption = Caption1
    dtgList.Columns(1).Caption = Caption2
    dtgList.Columns(2).Caption = "TIN No."
End Sub

